#include "Item.hh"
#include <sstream>

Item::Item(const std::string& n, const std::string& desc,
    unsigned health, unsigned attack, unsigned defense)
    : name(n), description(desc),
    healthBonus(health), attackBonus(attack), defenseBonus(defense) {
}

std::string Item::toString() const {
    std::string result = name;

    if (healthBonus > 0) {
        result += " (+";
        // Use stringstream instead of to_string
        std::stringstream ss;
        ss << healthBonus;
        result += ss.str();
        result += " life)";
    }

    if (attackBonus > 0) {
        result += " (+";
        // Use stringstream instead of to_string
        std::stringstream ss;
        ss << attackBonus;
        result += ss.str();
        result += " attack)";
    }

    if (defenseBonus > 0) {
        result += " (+";
        // Use stringstream instead of to_string
        std::stringstream ss;
        ss << defenseBonus;
        result += ss.str();
        result += " defense)";
    }

    return result;
}


//物品管理系统：
//这段代码实现了一个表示游戏物品的Item类，包含物品的属性及其字符串表示功能。通过 toString() 提供简洁的属性加成信息，适用于需要显示物品基础属性的场景（如背包菜单）。



//// Item Management System:
// This code implements an Item class that represents a game item, including the item's properties and its string representation. 
// toString() provides concise attribute markup information for scenarios that need to display the basic attributes of an item (such as the backpack menu).